import { defineStore } from 'pinia';

export const useUserStore = defineStore('userStore', {
  state: () => ({
    // 定义用户相关的状态
    username: '',
    email: '',
    testCurEx:1
  }),
  actions: {
    // 定义用户相关的操作
    setUsername(name: string) {
      this.username = name;
    },
    setEmail(mail: string) {
      this.email = mail;
    },
    setTestCurEx(num:number){
      this.testCurEx = num;
    }
  },
  // 启用持久化插件，并指定要持久化的属性
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'userStore',
        storage: localStorage,
        paths: ['username', 'email']
      }
    ]
  }
});